#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sets import Set

def isABCrightTriangle(abc):
    
    s2abc = sorted(abc)    
    return (s2abc[0]*s2abc[0]+s2abc[1]*s2abc[1]-s2abc[2]*s2abc[2]==0)
    
    

#print isABCrightTriangle([3,5,4])

def createTriangles(p):
    numberOfTriangles=0
    triSet = Set()
    triList=[]
    for a in range (1,p/2):
        for b in range (1,p/2):
            c=p-a-b
            abc=sorted([a,b,c])
            abcStr=str(abc)            
            if isABCrightTriangle(abc):
                if abcStr not in triSet:
                    #print abcStr
                    triSet.add(abcStr)
                    triList.append(abc)           
                    numberOfTriangles=numberOfTriangles+1
    #print "numberOfTriangles=",numberOfTriangles
    #print triList
    return [numberOfTriangles,p, triList]
       
list=[]
genlist=[]
#[8, 840, [[40, 399, 401], [56, 390, 394], [105, 360, 375], [120, 350, 370], [140, 336, 364], [168, 315, 357], [210, 280, 350], [240, 252, 348]]]
#correct answer
for p in range (820,842):
    print p
    list = createTriangles(p);
    if list[0]>0:
       genlist.append(list)
sgenlist = sorted(genlist) 
print sgenlist

last = sgenlist.pop()

print last

